home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / amiga-e / examples / virtual.e < prev   
Text File  |  1999-09-13  |  15KB  |  373 lines

  1. /*
  2. **  Original C Code written by Stefan Stuntz
  3. **
  4. **  Translation into E by Klaus Becker
  5. **
  6. **  All comments are from the C-Source
  7. */
  8.  
  9. OPT PREPROCESS
  10.  
  11. MODULE 'AmigaLib/boopsi'
  12. MODULE 'utility/tagitem'
  13. MODULE 'muimaster','libraries/mui','libraries/muip',
  14.        'intuition/classes','intuition/classusr'
  15.        
  16. DEF obj
  17. DEF bt1,bt2,bt3,bt4,gr,pcy,pgr
  18. DEF text1,text2,text3,
  19.     cya_computer,cya_printer,cya_display,
  20.     cy_computer,cy_printer,cy_display,
  21.     mt_computer,mt_printer,mt_display,
  22.     lv_computer,
  23.     bt_button0,bt_button1,bt_button2,bt_button3,bt_button4,bt_button5,
  24.     bt_button6,bt_button7,bt_button8,bt_button9,bt_button10,bt_button11,
  25.     x4sex,x4pages,x4classes,x4weapons,x4races
  26.  
  27. #define img(nr)  ImageObject, MUIA_Image_Spec, nr, End
  28.  
  29. #define mytxt(txt)\
  30.   TextObject,\
  31.     MUIA_Text_Contents,txt,\
  32.     MUIA_Text_SetMax, MUI_TRUE,\
  33.     End
  34.  
  35. #define ibt(i)\
  36.   ImageObject,\
  37.     ImageButtonFrame,\
  38.     MUIA_Background, MUII_ButtonBack,\
  39.     MUIA_InputMode , MUIV_InputMode_RelVerify,\
  40.     MUIA_Image_Spec, i,\
  41.     End
  42.  
  43. PROC makePage1()
  44.   text1:='\eiHello User !\en\n\n' +
  45.           'This could be a very long text and you are looking\n' +
  46.           'at it through a \euvirtual group\en. Please use the\n' +  
  47.           'scrollbars at the right and bottom of the group to\n' +
  48.           'move the visible area either vertically or\n' +
  49.           'horizontally. While holding down the small arrow\n' +
  50.           'button between both scrollbars, the display will\n' +
  51.           'follow your mouse moves.\n\n' +
  52.           'If you click somewhere into a \euvirtual group\en and\n' +
  53.           'move the mouse across one of its borders, the group will\n' +
  54.           'start scrolling. If you are lucky and own a middle mouse\n' +
  55.           'button, you may also want to press it and try moving.\n' +
  56.           '\n' +
  57.           'Note to 7MHz/68000 users: Sorry if you find this\n' +
  58.           'thingy a bit slow. Clipping in virtual groups can\n' +
  59.           'get quite complicated. Please don\at blame me,\n' +
  60.           'blame your \aout of date\a machine! :-)\n\n' +
  61.           '\ei\ecHave fun, Stefan.\en'
  62.  
  63.   obj := ScrollgroupObject,MUIA_Scrollgroup_UseWinBorder, MUI_TRUE,
  64.     MUIA_Scrollgroup_Contents, VirtgroupObject,
  65.       VirtualFrame,
  66.       Child, TextObject,
  67.         MUIA_Background, MUII_TextBack,
  68.         MUIA_Text_Contents, text1,
  69.       End,
  70.     End,
  71.   End
  72. ENDPROC (obj)
  73.  
  74. PROC makePage2()
  75.   text2:= '\ecAs you can see, this virtual group contains a\n'+
  76.           'lot of different objects. The (virtual) width\n'+
  77.           'and height of the virtual group are automatically\n'+
  78.           'calculated from the default width and height of\n'+
  79.           'the virtual groups contents.'
  80.  
  81.   obj := ScrollgroupObject,
  82.     MUIA_UserData, 42,
  83.     MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame,
  84.       MUIA_UserData, 42,
  85.       Child, TextObject,
  86.         TextFrame,
  87.         MUIA_Background, MUII_TextBack,
  88.         MUIA_Text_Contents, text2,
  89.       End,
  90.       Child, HGroup,
  91.         Child, ColGroup(2), GroupFrameT('Standard Images'),
  92.           Child, Label('ArrowUp:'    ), Child, img(MUII_ArrowUp    ),
  93.           Child, Label('ArrowDown:'  ), Child, img(MUII_ArrowDown  ),
  94.           Child, Label('ArrowLeft:'  ), Child, img(MUII_ArrowLeft  ),
  95.           Child, Label('ArrowRight:' ), Child, img(MUII_ArrowRight ),
  96.           Child, Label('RadioButton:'), Child, img(MUII_RadioButton),
  97.           Child, Label('File:'       ), Child, img(MUII_PopFile    ),
  98.           Child, Label('HardDisk:'   ), Child, img(MUII_HardDisk   ),
  99.           Child, Label('Disk:'       ), Child, img(MUII_Disk       ),
  100.           Child, Label('Chip:'       ), Child, img(MUII_Chip       ),
  101.           Child, Label('Drawer:'     ), Child, img(MUII_Drawer     ),
  102.         End,
  103.         Child, VGroup, GroupFrameT('Some Backgrounds'),
  104.           Child, HGroup,
  105.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_BACKGROUND , MUIA_FixWidth, 30, End,
  106.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILL       , MUIA_FixWidth, 30, End,
  107.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOW     , MUIA_FixWidth, 30, End,
  108.           End,
  109.           Child, HGroup,
  110.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWBACK , MUIA_FixWidth, 30, End,
  111.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWFILL , MUIA_FixWidth, 30, End,
  112.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWSHINE, MUIA_FixWidth, 30, End,
  113.           End,
  114.           Child, HGroup,
  115.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLBACK   , MUIA_FixWidth, 30, End,
  116.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHINEBACK  , MUIA_FixWidth, 30, End,
  117.             Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLSHINE  , MUIA_FixWidth, 30, End,
  118.           End,
  119.         End,
  120.       End,
  121.       Child, ColGroup(2), GroupFrame,
  122.         Child, Label1('Gauge:'), Child, GaugeObject, GaugeFrame, MUIA_Gauge_Current, 66, MUIA_Gauge_Horiz, TRUE, End,
  123.         Child, VSpace(0)       , Child, ScaleObject, End,
  124.       End,
  125.     End,
  126.   End
  127. ENDPROC (obj)
  128.  
  129. PROC makePage3()
  130.   text3:='\ecThe above pages only showed \aread only\a groups,\n' +
  131.          'no user actions within them were possible. Of course,\n' +
  132.          'handling user actions in a virtual group is not a\n' +
  133.          'problem for MUI. As I promised on the first page,\n' +
  134.          'you can use virtual groups with whatever objects\n' +
  135.          'you want. Here\as a small example...\n' +
  136.          '\n' +
  137.          'Note: Due to some limitations of the operating system,\n' + 
  138.          'it is not possible to clip gadgets depending on\n' +
  139.          'intuition.library correctly. This affects the appearence\n' +
  140.          'of string and proportional objects in virtual groups.\n' +
  141.          'You will only be able to use these gadgets when they\n' +
  142.          'are completely visible.\n' +
  143.          '\n' +
  144.          'PS: Also try TAB cycling here!'
  145.  
  146.   cya_computer:= ['Amiga 500','Amiga 600','Amiga 1000 :)','Amiga 1200','Amiga 2000','Amiga 3000','Amiga 4000', 'Amiga 4000T', 'Atari ST :(', NIL]
  147.   cya_printer:=['HP Deskjet','NEC P6','Okimate 20',NIL]
  148.   cya_display:=['A1081','NEC 3D','A2024','Eizo T660i',NIL]
  149.  
  150.   obj := ScrollgroupObject,
  151.     MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, 
  152.       Child, TextObject,
  153.         TextFrame,
  154.         MUIA_Background, MUII_TextBack,
  155.         MUIA_Text_Contents, text3,
  156.       End,
  157.       Child, VGroup,
  158.         Child, HGroup,
  159.           Child, mt_computer := Radio('Computer:',cya_computer),
  160.           Child, VGroup,
  161.             Child, mt_printer := Radio('Printer:',cya_printer),
  162.             Child, VSpace(0),
  163.             Child, mt_display := Radio('Display:',cya_display),
  164.           End,
  165.           Child, VGroup,
  166.             Child, ColGroup(2), GroupFrameT('Cycle Gadgets'),
  167.               Child, KeyLabel1('Computer:',"c"), Child, cy_computer := KeyCycle(cya_computer,"c"),
  168.               Child, KeyLabel1('Printer:' ,"p"), Child, cy_printer  := KeyCycle(cya_printer ,"p"),
  169.               Child, KeyLabel1('Display:' ,"d"), Child, cy_display  := KeyCycle(cya_display ,"d"),
  170.             End,
  171.             Child, lv_computer := ListviewObject,
  172.               MUIA_Listview_Input, MUI_TRUE,
  173.               MUIA_Listview_List, ListObject, InputListFrame, End,
  174.             End,
  175.           End,
  176.         End,
  177.         Child, ColGroup(4), GroupFrameT('Button Field'),
  178.           Child, bt_button0  := SimpleButton('Button'),
  179.           Child, bt_button1  := SimpleButton('Button'),
  180.           Child, bt_button2  := SimpleButton('Button'),
  181.           Child, bt_button3  := SimpleButton('Button'),
  182.           Child, bt_button4  := SimpleButton('Button'),
  183.           Child, bt_button5  := SimpleButton('Button'),
  184.           Child, bt_button6  := SimpleButton('Button'),
  185.           Child, bt_button7  := SimpleButton('Button'),
  186.           Child, bt_button8  := SimpleButton('Button'),
  187.           Child, bt_button9  := SimpleButton('Button'),
  188.           Child, bt_button10 := SimpleButton('Button'),
  189.           Child, bt_button11 := SimpleButton('Button'),
  190.         End,
  191.       End,
  192.     End,
  193.   End
  194.  
  195.   IF (lv_computer) THEN doMethodA(lv_computer,[MUIM_List_Insert,cya_computer,-1,MUIV_List_Insert_Bottom])
  196. ENDPROC (obj)
  197.  
  198. PROC makePage4()
  199.   
  200.   x4sex:=['male','female',NIL]
  201.   x4pages:=['Race','Class','Armors','Weapons','Levels',NIL]
  202.   x4races:=['Human','Elf','Dwarf','Hobbit','Gnome',NIL]
  203.   x4classes:=['Warrior','Rogue','Bard','Monk','Magician','Archmage',NIL]
  204.   x4weapons:=['Staff','Dagger','Sword','Axe','Grenade',NIL]
  205.  
  206.   obj := ScrollgroupObject,
  207.     MUIA_Scrollgroup_Contents, ColGroupV(3), VirtualFrame, 
  208.       MUIA_Group_Spacing, 10,
  209.       Child, VGroup, GroupFrame,
  210.         Child, HGroup,
  211.           Child, HSpace(0),
  212.           Child, bt1 := ibt(MUII_ArrowUp),
  213.           Child, HSpace(0),
  214.         End,
  215.         Child, HGroup,
  216.           Child, bt2 := ibt(MUII_ArrowLeft),
  217.           Child, bt3 := ibt(MUII_ArrowRight),
  218.         End,
  219.         Child, HGroup,
  220.           Child, HSpace(0),
  221.           Child, bt4 := ibt(MUII_ArrowDown),
  222.           Child, HSpace(0),
  223.         End,
  224.       End,
  225.       Child, mytxt('\ecEver wanted to see\na virtual group in\na virtual group?'),
  226.       Child, HVSpace,
  227.       Child, mytxt('\ecHere it is!'),
  228.       Child, ScrollgroupObject,
  229.         MUIA_Scrollgroup_Contents, gr := VGroupV, VirtualFrame,
  230.           Child, ColGroup(6), MUIA_Group_SameSize, MUI_TRUE,
  231.             Child, SimpleButton('One'),
  232.             Child, SimpleButton('Two'),
  233.             Child, SimpleButton('Three'),
  234.             Child, SimpleButton('Four'),
  235.             Child, SimpleButton('Five'),
  236.             Child, SimpleButton('Six'),
  237.             Child, SimpleButton('Eighteen'),
  238.             Child, mytxt('\ecThe'),
  239.             Child, mytxt('\ecred'),
  240.             Child, mytxt('\ecbrown'),
  241.             Child, mytxt('\ecfox'),
  242.             Child, SimpleButton('Seven'),
  243.             Child, SimpleButton('Seventeen'),
  244.             Child, mytxt('\ecdog.'),
  245.             Child, SimpleButton('Nineteen'),
  246.             Child, SimpleButton('Twenty'),
  247.             Child, mytxt('\ecjumps'),
  248.             Child, SimpleButton('Eight'),
  249.             Child, SimpleButton('Sixteen'),
  250.             Child, mytxt('\eclazy'),
  251.             Child, mytxt('\ecthe'),
  252.             Child, mytxt('\ecover'),
  253.             Child, mytxt('\ecquickly'),
  254.             Child, SimpleButton('Nine'),
  255.             Child, SimpleButton('Fifteen'),
  256.             Child, SimpleButton('Fourteen'),
  257.             Child, SimpleButton('Thirteen'),
  258.             Child, SimpleButton('Twelve'),
  259.             Child, SimpleButton('Eleven'),
  260.             Child, SimpleButton('Ten'),
  261.           End,
  262.         End,
  263.       End,
  264.       Child, mytxt('\ecDo you like it? I hope...'),
  265.       Child, HVSpace,
  266.       Child, mytxt('\ecI admit, it\as a\n bit crazy... :-)\nBut it demonstrates\nthe power of\n\ebobject oriented\en\nGUI design.'),
  267.       Child, ScrollgroupObject,
  268.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, InnerSpacing(4,4), 
  269.           Child, VGroup,
  270.             Child, pcy := Cycle(x4pages),
  271.             Child, pgr := PageGroup,
  272.               Child, HCenter(Radio(NIL,x4races)),
  273.               Child, HCenter(Radio(NIL,x4classes)),
  274.               Child, HGroup,
  275.                 Child, HSpace(0),
  276.                 Child, ColGroup(2),
  277.                   Child, Label1('Cloak:' ), Child, CheckMark(MUI_TRUE),
  278.                   Child, Label1('Shield:'), Child, CheckMark(MUI_TRUE),
  279.                   Child, Label1('Gloves:'), Child, CheckMark(MUI_TRUE),
  280.                   Child, Label1('Helm:'  ), Child, CheckMark(MUI_TRUE),
  281.                 End,
  282.                 Child, HSpace(0),
  283.               End,
  284.               Child, HCenter(Radio(NIL,x4weapons)),
  285.               Child, ColGroup(2),
  286.                 Child, Label('Experience:'  ), Child, Slider(0,100, 3),
  287.                 Child, Label('Strength:'    ), Child, Slider(0,100,42),
  288.                 Child, Label('Dexterity:'   ), Child, Slider(0,100,24),
  289.                 Child, Label('Condition:'   ), Child, Slider(0,100,39),
  290.                 Child, Label('Intelligence:'), Child, Slider(0,100,74),
  291.               End,
  292.             End,
  293.           End,
  294.         End,
  295.       End,
  296.     End,
  297.   End
  298.  
  299.   IF (obj)
  300.     doMethodA(bt1,[MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,0])
  301.     doMethodA(bt2,[MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,0])
  302.     doMethodA(bt3,[MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,9999])
  303.     doMethodA(bt4,[MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,9999])
  304.     doMethodA(pcy,[MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  305.       pgr,3,MUIM_Set,MUIA_Group_ActivePage,MUIV_TriggerValue])
  306.   ENDIF
  307.  
  308. ENDPROC (obj)
  309.  
  310. PROC main() HANDLE
  311.   DEF app,window,sigs=0
  312.  
  313.   IF (muimasterbase:=OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))=NIL THEN
  314.     Raise('Failed to open muimaster.library')
  315.  
  316.   app := ApplicationObject,
  317.     MUIA_Application_Title      , 'VirtualDemo',
  318.     MUIA_Application_Version    , '$VER: VirtualDemo 13.59 (30.01.96)',
  319.     MUIA_Application_Copyright  , 'c1993, Stefan Stuntz',
  320.     MUIA_Application_Author     , 'Stefan Stuntz & Klaus Becker',
  321.     MUIA_Application_Description, 'Show virtual groups.',
  322.     MUIA_Application_Base       , 'VIRTUALDEMO',
  323.     SubWindow, window := WindowObject,
  324.       MUIA_Window_Title, 'Virtual Groups',
  325.       MUIA_Window_ID   , "VIRT",
  326.       MUIA_Window_UseRightBorderScroller, MUI_TRUE,
  327.       MUIA_Window_UseBottomBorderScroller, MUI_TRUE,
  328.       WindowContents, ColGroup(2), GroupSpacing(8),
  329.         Child, makePage1(),
  330.         Child, makePage2(),
  331.         Child, makePage3(),
  332.         Child, makePage4(),
  333.       End,
  334.     End,
  335.   End
  336.  
  337.   IF (app=NIL) THEN
  338.     Raise('Failed to create Application.')
  339.  
  340.   doMethodA(window,[MUIM_Notify,MUIA_Window_CloseRequest,MUI_TRUE,
  341.     app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit])
  342.  
  343.   doMethodA(window,[MUIM_Window_SetCycleChain,
  344.     mt_computer,mt_printer,mt_display,
  345.     cy_computer,cy_printer,cy_display,
  346.     lv_computer,
  347.     bt_button0,bt_button1,bt_button2,bt_button3,
  348.     bt_button4,bt_button5,bt_button6,bt_button7,
  349.     bt_button8,bt_button9,bt_button10,bt_button11,
  350.     NIL])
  351.  
  352. /*
  353. ** This is the ideal input loop for an object oriented MUI application.
  354. ** Everything is encapsulated in classes, no return ids need to be used,
  355. ** we just check if the program shall terminate.
  356. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  357. ** from Wait() (or 0). This makes the input loop significantly faster.
  358. */
  359.  
  360.   set(window,MUIA_Window_Open,MUI_TRUE)
  361.  
  362.   WHILE (doMethodA(app,[MUIM_Application_NewInput,{sigs}]) <> MUIV_Application_ReturnID_Quit)
  363.     IF sigs THEN sigs:=Wait(sigs)
  364.   ENDWHILE
  365.  
  366.   set(window,MUIA_Window_Open,FALSE)
  367.  
  368. EXCEPT DO
  369.   IF app THEN Mui_DisposeObject(app)
  370.   IF muimasterbase THEN CloseLibrary(muimasterbase)
  371.   IF exception THEN WriteF('\s\n',exception)
  372. ENDPROC
  373.